<template>
  <div class="container">
    <el-form ref="elForm" :model="queryObj" :rules="rules" label-width="165px">
      <el-form-item label="单行文本" prop="field101">
        <el-input v-model="queryObj.field101" placeholder="请输入单行文本单行文本" clearable :style="{ width: '100%' }">
        </el-input>
      </el-form-item>
      <el-form-item label="下拉选择" prop="field102">
        <el-select
          filterable
          v-model="queryObj.field102"
          placeholder="请选择下拉选择"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in field102Options"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="多行文本" prop="field104">
        <el-input
          v-model="queryObj.field104"
          type="textarea"
          placeholder="请输入多行文本"
          :autosize="{ minRows: 4, maxRows: 4 }"
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-form-item label="单选框组" prop="field105">
        <el-radio-group v-model="queryObj.field105">
          <el-radio
            v-for="(item, index) in field105Options"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
      <el-form-item label="多选框组" prop="field106">
        <el-checkbox-group v-model="queryObj.field106">
          <el-checkbox
            v-for="(item, index) in field106Options"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="日期范围" prop="field107">
        <el-date-picker
          type="daterange"
          v-model="queryObj.field107"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          :style="{ width: '100%' }"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          range-separator="至"
          clearable
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'FormInput',
  data() {
    return {
      queryObj: {
        field101: undefined,
        field102: undefined,
        field104: undefined,
        field105: undefined,
        field106: [],
        field107: null
      },
      rules: {
        field101: [
          {
            required: true,
            message: '请输入单行文本单行文本',
            trigger: 'blur'
          }
        ],
        field102: [
          {
            required: true,
            message: '请选择下拉选择',
            trigger: 'change'
          }
        ],
        field104: [
          {
            required: true,
            message: '请输入多行文本',
            trigger: 'blur'
          }
        ],
        field105: [
          {
            required: true,
            message: '单选框组不能为空',
            trigger: 'change'
          }
        ],
        field106: [
          {
            required: true,
            type: 'array',
            message: '请至少选择一个多选框组',
            trigger: 'change'
          }
        ],
        field107: [
          {
            required: true,
            message: '日期范围不能为空',
            trigger: 'change'
          }
        ]
      },
      field102Options: [
        {
          label: '选项一',
          value: 1
        },
        {
          label: '选项二',
          value: 2
        }
      ],
      field105Options: [
        {
          label: '选项一',
          value: 1
        },
        {
          label: '选项二',
          value: 2
        }
      ],
      field106Options: [
        {
          label: '选项一',
          value: 1
        },
        {
          label: '选项二',
          value: 2
        }
      ]
    }
  },
  methods: {
    submitForm() {
      this.$refs.elForm.validate(valid => {
        // eslint-disable-next-line no-useless-return
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs.elForm.resetFields()
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  background-image: radial-gradient(50% 92%, #003164 50%, #002a52 93%);
  box-sizing: border-box;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
</style>
